package com.zwps.biz.controller.http;

import java.util.List;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zwps.biz.api.model.dto.permission.page.AddPagePermissionDTO;
import com.zwps.biz.api.model.dto.permission.page.UpdatePagePermissionDTO;
import com.zwps.biz.api.model.vo.permission.page.PagePermissionTreeVO;
import com.zwps.biz.domain.service.PagePermissionService;
import com.zwps.common.controller.CommonController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 系统页面权限
 * 
 * @ClassName: PagePermissionController
 * @Description: 
 * @author lyh
 * @date 2023年5月25日 下午2:11:11
 *
 */
@Tag(name = "页面权限管理")
@RestController
@RequestMapping("system/page_permission")
@Validated
public class PagePermissionController extends CommonController {

    @Autowired
    private PagePermissionService pagePermissionService;

    @Operation(summary = "新增页面权限")
    @PostMapping
    public void addPagePermission(@Valid @NotNull @RequestBody AddPagePermissionDTO dto) {
        pagePermissionService.addPagePermission(dto);
    }

    @Operation(summary = "删除页面权限")
    @DeleteMapping("{ids}")
    public void deletePagePermissions(@Valid @NotBlank @PathVariable String ids) {
        pagePermissionService.deletePagePermissions(ids);
    }

    @Parameter(name = "id", description = "页面权限ID", in = ParameterIn.PATH)
    @Operation(summary = "修改页面权限信息")
    @PutMapping("{id}")
    public void updatePagePermission(@Valid @NotBlank @PathVariable String id,
            @Valid @NotNull @RequestBody UpdatePagePermissionDTO dto) {
        pagePermissionService.updatePagePermission(id, dto);
    }
    
    @Parameter(name = "parentId", description = "上级ID")
    @Operation(summary = "查询页面权限树")
    @GetMapping("tree")
    public List<PagePermissionTreeVO> findDeptTree(@Nullable String parentId) {
        return pagePermissionService.findTree(parentId);
    }
}
